﻿<?php
class dynamicWeb {
    public static function getDynamicWeb($webId,$userName){		
	
       // $webInfoArr = self::getWebInfo($webId);
        //var_dump($webInfoArr);
        //echo $webInfoArr;
        
       	$WebInfoModel = M("module_dynamic_web");
		$WebInfoArr = $WebInfoModel->where("id=".$webId."")->find();
        
      //  echo $WebInfoModel->getLastSql();
        if($WebInfoArr){
            $dynamicWebArr = self::getDynamicWebList($webId);
            $dynamicWebnum=count($dynamicWebArr );
            $WebInfoArr['dynamicWebnum'] = $dynamicWebnum;
            //$result = array();
           // $result['WebInfo'] = $WebInfoArr;
            $WebInfoArr['dynamicWebs'] = $dynamicWebArr;
            //ihziluoh 添加标签
			if(!empty($WebInfoArr['tagNames']) && !empty($userName)){	
				setAccessTags($WebInfoArr['tagNames'],$userName,module_handle_dynamicWeb, $webId);
			}
			//ihziluoh 添加标签
			Output::instance()->module('dynamicWeb', 'dynamicWeb')->object($WebInfoArr);
            
			
		}else{
			Output::instance()->resultCode(code_red_envelope_activity_has_end);
		}      	
	}   
    //获取页面列表
    public static function getDynamicWebList($webId) {	
    	$result = array();
    	
	//	$customerId = Session::$user["customerId"];
     //  echo $webId;
		$DynamicWebModel = M("module_dynamic_web_page");
		$dynamicWebArr=$DynamicWebModel->where("webId=".$webId."")->order("sequence asc")->select();
        $i=0;
        foreach($dynamicWebArr as $value){            
         // $allId.=','.$value[id];   
        $ElementArr = self::getElementList($value['id']);
        $dynamicWebArr[$i]['Element']=$ElementArr;
        $i++;
        }
      //  $result['dynamicWebs'] = $dynamicWebArr;
		return $dynamicWebArr;
	}
    //获取每个页面所有元素
    public static function getElementList($webPageId) {	
		//$customerId = Session::$user["customerId"];  
		$ElementModel = M("module_dynamic_web_page_element");
		$ElementArr=$ElementModel->where("webPageId=".$webPageId."")->select();
		return $ElementArr;
	}
	
     public static function getWebInfo($id) {	
		//$customerId = Session::$user["customerId"];  
		$WebInfoModel = M("module_dynamic_web");
		$WebInfoArr = $WebInfoModel->where("id=".$id."")->find();
        
      //  echo $WebInfoModel->getLastSql();
        //$result['WebInfo'] = $WebInfoArr;
       // var_dump($WebInfoArr);
		return $WebInfoArr;
	}
    
    
    
}	